*****************************************************************************************************

This folder contains example codes for the PPI Interface(2) between the SD card and Blackfin 
processors.

The SD card is interfaced to Blackfin through the Parallel Peripheral Interface (PPI). The parallel 
port is used so as to implement the bidirectional data/ command protocol of the SD card. It can 
support the 4-bit SD mode. One of the PPI data lines (PPID4) is used for the command/response 
transfer. 

*****************************************************************************************************

EZ-KIT Lite Switch settings:

1. Unpopulate JP2
2. SW13.4 = ON

*****************************************************************************************************

Algorithms for the software

Setup N clock cycles to the SD card
1) Configure TMR7 in PWM out mode to generate a continuous clock
2) Configure TMR6 to generate a single pulse, of width equal to the number of clock cycles that need 
   to be generated
3) Enable both timers

Setup a continuous SD Card clock
1) Configure TMR6 as a GPIO output
2) Drive HI on this pin
3) Configure TMR7 in PWM out mode to generate a continuous clock
4) Enable TMR7
5) Drive LO on GPIO to stop the clock 

Setup a continuous Blackfin clock
1) Configure TMR4 as a GPIO output
2) Drive HI on this pin
3) Configure TMR7 in PWM out mode to generate a continuous clock
4) Enable TMR7
5) Drive LO on GPIO to stop the clock 

Setup N clock cycles to Blackfin PPI
1) Configure TMR7 in PWM out mode to generate a continuous clock
2) Configure TMR6 to generate a single pulse, of width equal to the number of clock cycles that need 
   to be generated
3) Enable both timers

Setup N clocks to Blackfin PPI and the SD card
1) Configure TMR7 in PWM out mode to generate a continuous clock
2) Configure TMR4 and TMR6 to generate a single pulse, of width equal to the number of clock cycles 
   that need to be generated
3) Enable TMR4, TMR6 and TMR7

Frame sync generation for PPI Transmit
1) Configure TMR0 to derive clock from PPI clock and generate a single pulse
2) Enable TMR0

Receive Response
1) Setup and enable DMA to receive Response length + 24* number of words
2) Setup and enable PPI to receive in 0 Frame Sync GP mode with internal trigger
3) Send 8 clock cycles only to Blackfin *
4) Send Response length + 24 number of clock cycles to both PPI and SD card
5) Disable PPI in the DMA ISR
6) Extract Response
	a. Detect the first 0 in the buffer  this is the start bit
	b. Extract bit 0 from every word out of Response length number of words to form the complete 
           response
* When PPI is used in receive mode with 0 frame syncs, a delay of at least 2 clock cycles is present 
before actual data is received. In this approach, 8 extra words are received to account for this delay. 
The card transmits the first 0 after a variable number of clocks after receiving the stop bit of the 
command. This amounts to a total of 24 extra clocks. 

Send Command
1) Send 12 SD Clocks  minimum 8 needed as per the SD Spec
2) Setup command array
	a. Fill up the command buffer
	b. Compute CRC7
	c. Rearrange the command word to occupy only bit 4 of every PPI Command word
3) Setup and enable DMA to transmit 48 words (equivalent to 48 bits on the CMD line)
4) Setup and enable PPI in 1 Frame Sync GP mode to transmit 48 words.
5) Generate FS and send 4 clock cycles only to Blackfin (to account for PPI delays)
6) Send 48 clock cycles to both PPI and SD card
7) Check for DMA_RUN bit to be cleared and then disable PPI
